﻿package mortal.game.view.lookPlayerInfo.view
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.core.frame.*;
    import flash.events.*;
    import frEngine.effectEditTool.temple.*;
    import frEngine.pools.*;
    import mortal.component.window.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.model.player.weapon.*;
    import mortal.game.scene3D.model.pools.*;
    import mortal.game.scene3D.player.type.*;
    import mortal.game.view.common.*;

    public class LookWeaponInfoPanel extends LookSystemBasePanel
    {
        private var _weaponPlayer:WeaponPlayer;
        private var _frameTimer:FrameTimer;
        private var _turnNum:Number = 0;

        public function LookWeaponInfoPanel(param1:Window)
        {
            super(param1);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            if (this._weaponPlayer)
            {
                _rect3d.disposeObj3d(this._weaponPlayer);
                this._weaponPlayer = null;
            }
            super.disposeImpl(param1);
            return;
        }// end function

        override protected function update3DModel() : void
        {
            var _loc_1:int = 0;
            var _loc_2:TPlayerModel = null;
            if (_rect3d)
            {
                if (_slookPlayerMountInfo.shape > 10)
                {
                    _loc_1 = (ItemConfig.instance.getConfig(_slookPlayerMountInfo.shape) as ItemEquipInfo).modelId;
                }
                else
                {
                    _loc_1 = _tmountInfo.modelId;
                }
                _loc_2 = PlayerModelConfig.instance.getModelInfo(ModelType.WEAPONS, _loc_1, 1, _sLookPlayerInfo.miniPlayer.career);
                if (this._weaponPlayer == null)
                {
                    this._weaponPlayer = FrObjectPool.getObject(WeaponPlayer, this);
                }
                this._weaponPlayer.load(_loc_2.mesh + ".md5mesh", _loc_2.texture, _rect3d.renderList);
                this._weaponPlayer.enabledPool = false;
                this._weaponPlayer.scaleX = 1.8;
                this._weaponPlayer.scaleY = 1.8;
                this._weaponPlayer.scaleZ = 1.8;
                this._weaponPlayer.rotationZ = -20;
                this.reset3dModelPos();
                this.stopTurn();
                if (this._frameTimer == null)
                {
                    this._frameTimer = new FrameTimer();
                    this._frameTimer.addListener(TimerType.ENTERFRAME, this.onTimerFrameHandler);
                }
                this._frameTimer.start();
                if (_loc_2 && _loc_2.selfEffect && VipConfig.instance.isShowEffect(EVipRecordType._EVipRecordTypeWeaponEffect, _sLookPlayerInfo.miniPlayer.VIP))
                {
                    if (_effectPlayer)
                    {
                        _effectPlayer.dispose(true);
                        _effectPlayer = null;
                    }
                    _effectPlayer = EffectPlayerPool.instance.getEffectPlayer(_loc_2.selfEffect, this._weaponPlayer, _rect3d.renderList, true);
                    if (_effectPlayer.temple is TempleRole)
                    {
                        (_effectPlayer.temple as TempleRole).setRoleParams(this._weaponPlayer, null, null);
                    }
                    _effectPlayer.play();
                }
            }
            return;
        }// end function

        override protected function reset3dModelPos(param1:TModel = null) : void
        {
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            switch(_sLookPlayerInfo.miniPlayer.career)
            {
                case ECareer._ECareerWarrior:
                {
                    _loc_2 = 132 + 94;
                    _loc_3 = 280 + 20;
                    break;
                }
                case ECareer._ECareerArcher:
                {
                    _loc_2 = 132 + 20 + 94;
                    _loc_3 = 240 - 30 + 20;
                    break;
                }
                case ECareer._ECareerMage:
                {
                    _loc_2 = 132 + 94;
                    _loc_3 = 240 + 20;
                    break;
                }
                default:
                {
                    break;
                }
            }
            _rect3d.addObject3d(this._weaponPlayer, _loc_2, _loc_3);
            return;
        }// end function

        override protected function addOtherObj() : void
        {
            var _loc_1:* = ImagesConst.Fashion_ArtifactSkillText;
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(_loc_1, 212 + 4 + 3, 429 + 32, _window.contentTopOf3DSprite));
            return;
        }// end function

        private function onTimerFrameHandler(param1:FrameTimer) : void
        {
            this.modelTurn();
            return;
        }// end function

        override protected function onClickTurnBtn(event:MouseEvent) : void
        {
            if (this._weaponPlayer)
            {
                if (event.currentTarget == _leftBtn)
                {
                    turnValue = 2;
                }
                if (event.currentTarget == _rightBtn)
                {
                    turnValue = -2;
                }
                start();
            }
            return;
        }// end function

        private function stopTurn() : void
        {
            if (this._frameTimer)
            {
                this._frameTimer.stop();
            }
            this._turnNum = 0;
            return;
        }// end function

        private function modelTurn() : void
        {
            if (this._weaponPlayer)
            {
                var _loc_1:* = this._turnNum + 0.1;
                this._turnNum = this._turnNum + 0.1;
                this._weaponPlayer.y = this._weaponPlayer.y + Math.cos(_loc_1) * 1;
                this._weaponPlayer.rotationY = this._weaponPlayer.rotationY + 5;
            }
            return;
        }// end function

        override protected function onTurning(param1:FrameTimer) : void
        {
            return;
        }// end function

        override protected function turning(event:MouseEvent) : void
        {
            return;
        }// end function

    }
}
